Cosine Similarity


Before getting into the cosine similarity function remember that the norm of a vector is defined as:

v=i=1nvi2\| \vec{v} \| = \sqrt{\sum_{i=1}^{n} |v_i|^2 }

The dot product is then defined as:

vw=i=1nviwi \vec{v} \cdot \vec{w} = \sum_{i=1}^{n} v_i \cdot w_i

The following cosine similarity equation makes sense:

cos(β)=v^w^v^w^ \cos (\beta) = \frac{\hat v \cdot \hat w}{\| \hat v \| \| \hat w \|}

If v^\hat v and w^\hat w are the same then you get the numerator to be equal to the denominator. Hence β=0\beta = 0. On the other hand, the dot product of two orthogonal (perpendicular) vectors is 00. That takes place when β=90\beta = 90.

 Complete